import { formType, formStatus, colorStatus } from '@/views/formConst'
import {
  STATUS_TYPE_DRAFT,
  STATUS_TYPE_PENDING,
  STATUS_TYPE_REVIEW,
  STATUS_TYPE_APPROVED,
  STATUS_TYPE_REJECTED,
  STATUS_TYPE_FINISH,
  STATUS_TYPE_PUBLISHED,
  STATUS_TYPE_TERMINATED
} from '@/views/formConst'
export function formColumns() {
  return [
    {
      type: 'selection',
      width: 50,
      align: 'center'
    },
    {
      title: '表单名称',
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              transfer: true,
              maxWidth: '1000',
              content: params.row.name,
              trigger: 'hover',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h(
              'div',
              {
                style: {
                  color: 'var(--link-color)',
                  cursor: 'pointer'
                },
                on: {
                  click: () => {
                    this.editBaseForm(params.row)
                  }
                }
              },
              params.row.name
            )
          ]
        )
      }
    },
    {
      title: '模板类型',
      width: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', {}, formType.find(item => item.key === params.row.type).name)
      }
    },
    {
      title: '年份',
      width: 110,
      align: 'center',
      key: 'year'
    },
    {
      title: '当前填报周期',
      width: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', {}, params.row.period || '--')
      }
    },
    {
      title: '创建人',
      width: 140,
      align: 'center',
      key: 'creator'
    },
    {
      title: '最后更新时间',
      width: 160,
      align: 'center',
      key: 'updateTime'
    },
    {
      title: '备注',
      width: 150,
      align: 'center',
      key: 'remark'
    },
    {
      title: '状态',
      align: 'center',
      width: 150,
      render: (h, params) => {
        let color = colorStatus[params.row.status]
        let name = formStatus.find(item => item.key === params.row.status).name || '--'
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 320,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '编辑',
                optType:
                  this.userCode === params.row.createBy &&
                  [STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status)
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.editForm(params.row)
                }
              },
              {
                type: 'text',
                text: '复制',
                // optType: [
                //   STATUS_TYPE_APPROVED,
                //   STATUS_TYPE_FINISH,
                //   STATUS_TYPE_PUBLISHED,
                //   STATUS_TYPE_TERMINATED
                // ].includes(params.row.status)
                //   ? ''
                //   : 'ashing',
                handle: () => {
                  this.copyForm(params.row)
                }
              },
              {
                type: 'text',
                text: '删除',
                optType:
                  this.userCode === params.row.createBy &&
                  [STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status)
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.deleteForm(params.row)
                }
              },
              {
                type: 'text',
                text: '预览',
                optType: ![STATUS_TYPE_DRAFT].includes(params.row.status) ? '' : 'ashing',
                handle: () => {
                  this.previewForm(params.row)
                }
              },
              {
                type: 'text',
                text: params.row.bpmpId ? '查看流程' : '关联流程',
                optType:
                  this.userCode === params.row.createBy &&
                  [STATUS_TYPE_APPROVED, STATUS_TYPE_FINISH, STATUS_TYPE_PUBLISHED, STATUS_TYPE_TERMINATED].includes(
                    params.row.status
                  )
                    ? ''
                    : 'ashing',
                handle: () => {
                  if (params.row.bpmpId) {
                    this.viewFormBpm(params.row)
                  } else {
                    this.configFormBpm(params.row)
                  }
                }
              },
              {
                type: 'text',
                text: '历史填报周期',
                optType: [STATUS_TYPE_FINISH, STATUS_TYPE_PUBLISHED, STATUS_TYPE_TERMINATED].includes(params.row.status)
                  ? ''
                  : 'ashing',
                handle: () => {
                  this.viewHistory(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

export const columnListToRead = [
  { columnKey: 'mailTitle', columnName: '标题', disabled: true },
  { columnKey: 'content', columnName: '提醒内容' },
  { columnKey: 'sponsor', columnName: '发起人' },
  { columnKey: 'createTime', columnName: '发起时间' }
]

export const columnListRead = [
  { columnKey: 'mailTitle', columnName: '标题', disabled: true },
  { columnKey: 'content', columnName: '提醒内容' },
  { columnKey: 'sponsor', columnName: '发起人' },
  { columnKey: 'triggerTime', columnName: '发起时间' },
  { columnKey: 'updateTime', columnName: '处理时间' }
]
